﻿Public Class PaymentView

    Private Sub PaymentView_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        UI.FormatDataGrid(DataGridView1)
        UI.SetPlaceHolder(txtsearch)
        loadpaymethod()
        loadpayment()
    End Sub

    Private Sub loadpayment()
        Dim sql = <sql>
                        SELECT p.*,c.CheckInNo,cl.ClientName,pm.PaymentMethod
                        FROM Payment p
                        INNER JOIN CheckIn c on c.CheckInId=p.CheckInId
                        INNER JOIN Client cl on cl.ClientId=c.ClientId
                        INNER JOIN PaymentMethod pm on pm.PaymentMethodId=p.PaymentMethodId
                        WHERE p.Active=1
                            AND (@pMethod=0 OR p.PaymentMethodId=@pMethod) 
                            AND UPPER(ClientName) LIKE UPPER(@S);
                  </sql>
        cmd.Parameters("@pMethod") = cbopaymethod.SelectedValue
        cmd.Parameters("@S") = "%" + txtsearch.Text + "%"
        DataGridView1.DataSource = cmd.ExecuteDataTable(sql)
    End Sub
    Private Sub loadpaymethod()
        cbopaymethod.DisplayMember = "PaymentMethod"
        cbopaymethod.ValueMember = "PaymentMethodId"
        cbopaymethod.DataSource = cmd.ExecuteDataTable("SELECT PaymentMethodId,PaymentMethod FROM PaymentMethod WHERE Active=1 UNION SELECT 0,'All'")

    End Sub

    Private Sub txtsearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsearch.TextChanged
        loadpayment()
    End Sub

    Private Sub cbopaymethod_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbopaymethod.SelectedIndexChanged
        loadpayment()
    End Sub
    
End Class